package com.om.abom.utils;

import lombok.Data;

import java.io.Serializable;

/**
 * 后端统一返回结果
 *
 * @param <T>
 */
@Data
public class R<T> implements Serializable
{
    private Integer code;   //编码：0成功，1和其它数字为失败
    private String msg;     //错误信息
    private T data;         //数据

    public static <T> R<T> success()
    {
        R<T> result = new R<>();
        result.code = 0;
        result.msg = "success";
        return result;
    }

    public static <T> R<T> success(T object)
    {
        R<T> result = new R<>();
        result.data = object;
        result.code = 0;
        result.msg = "success";
        return result;
    }

    public R<T> message(String msg)
    {
        this.msg = msg;
        return this;
    }

    public static <T> R<T> error(String msg)
    {
        R<T> result = new R<>();
        result.msg = msg;
        result.code = 1;
        return result;
    }
}
